<?php

/**
 * This is the model class for table "{{modules}}".
 *
 * The followings are the available columns in table '{{modules}}':
 * @property integer $module_id
 * @property integer $admin_id
 * @property string $module_code
 * @property string $module_name
 * @property string $module_type
 * @property integer $parent_id
 * @property string $platform_type
 * @property string $app_type
 * @property string $ext_attribute
 * @property string $status
 */
class Modules extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Modules the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return '{{modules}}';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('admin_id, module_code, module_name, parent_id, ext_attribute', 'required'),
			array('admin_id, parent_id', 'numerical', 'integerOnly'=>true),
			array('module_code', 'length', 'max'=>32),
			array('module_name', 'length', 'max'=>100),
			array('module_type', 'length', 'max'=>10),
			array('platform_type, status', 'length', 'max'=>7),
			array('app_type', 'length', 'max'=>4),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('module_id, admin_id, module_code, module_name, module_type, parent_id, platform_type, app_type, ext_attribute, status', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'module_id' => 'Module',
			'admin_id' => 'Admin',
			'module_code' => 'Module Code',
			'module_name' => 'Module Name',
			'module_type' => 'Module Type',
			'parent_id' => 'Parent',
			'platform_type' => 'Platform Type',
			'app_type' => 'App Type',
			'ext_attribute' => 'Ext Attribute',
			'status' => 'Status',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('module_id',$this->module_id);
		$criteria->compare('admin_id',$this->admin_id);
		$criteria->compare('module_code',$this->module_code,true);
		$criteria->compare('module_name',$this->module_name,true);
		$criteria->compare('module_type',$this->module_type,true);
		$criteria->compare('parent_id',$this->parent_id);
		$criteria->compare('platform_type',$this->platform_type,true);
		$criteria->compare('app_type',$this->app_type,true);
		$criteria->compare('ext_attribute',$this->ext_attribute,true);
		$criteria->compare('status',$this->status,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}